package com.tjp.eight.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.app.FragmentActivity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.tjp.eight.R;
import com.tjp.eight.WApplication;

/**
 * Created by Administrator on 2017/3/10.
 */

public class ToatUtils {
    public static void toastCommentSuccess(Context context) {
        Toast toast = new Toast(context);
        View view = LayoutInflater.from(context).inflate(R.layout.toat_comment_success, null);

        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.setDuration(Toast.LENGTH_SHORT);

        toast.setView(view);
        toast.show();
    }

    public static void toastCommentSuccess(Context context, String msg) {
        Toast toast = new Toast(context);
        View view = LayoutInflater.from(context).inflate(R.layout.toat_comment_success, null);
        TextView tips = (TextView) view.findViewById(R.id.tv_toast_tips);
        tips.setText("" + msg);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.setDuration(Toast.LENGTH_SHORT);

        toast.setView(view);
        toast.show();
    }

    public static void toastSuccess(Context context, String msg) {
        Toast toast = new Toast(context);
        View view = LayoutInflater.from(context).inflate(R.layout.toat_success, null);
        TextView tips = (TextView) view.findViewById(R.id.tv_toast_tips);
        tips.setText("" + msg);
        toast.setGravity(Gravity.BOTTOM, 0, 45);
        toast.setDuration(Toast.LENGTH_SHORT);

        toast.setView(view);
        toast.show();
    }

    public static void toastCommentFail(Context context, String msg) {
        Toast toast = new Toast(context);
        View view = LayoutInflater.from(context).inflate(R.layout.toat_comment_success, null);
        ImageView imageView = (ImageView) view.findViewById(R.id.iv_toast);
        TextView tips = (TextView) view.findViewById(R.id.tv_toast_tips);
        imageView.setImageBitmap(BitmapUtils.getBitmap(context, R.drawable.toast_icon_n));
        tips.setText("" + msg);

        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.setView(view);
        toast.show();
    }

    public static void toastBit(Context context, String msg, Bitmap bitmap) {
        Toast toast = new Toast(context);
        View view = LayoutInflater.from(context).inflate(R.layout.toat_comment_success, null);
        ImageView imageView = (ImageView) view.findViewById(R.id.iv_toast);
        TextView tips = (TextView) view.findViewById(R.id.tv_toast_tips);
        if (bitmap != null)
            imageView.setImageBitmap(bitmap);
        else
            imageView.setImageBitmap(BitmapUtils.getBitmap(context, R.drawable.toast_icon_n));
        tips.setText("" + msg);

        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.setView(view);
        toast.show();
    }

    private static Toast noInstall= new Toast(WApplication.getInstance());
    public static void toastNoInstall(Context context, String msg) {
        //Toast toast = new Toast(context);
        View view = LayoutInflater.from(context).inflate(R.layout.toat_success, null);
        TextView tips = (TextView) view.findViewById(R.id.tv_toast_tips);
        tips.setText("" + msg);
        noInstall.setGravity(Gravity.BOTTOM, 0, 45);
        noInstall.setDuration(Toast.LENGTH_SHORT);

        noInstall.setView(view);
        noInstall.show();
    }
}
